<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  

 <script>
  let userAge = []
   let frequency = 1
   // 需求1
   while (frequency<=5 ) {
       let age = +prompt('请输入有效年龄')
        if (age>=0 && age<=100) {
          userAge.push(age)
          frequency++
        } else {
          alert('无效的年龄，请重新输入')
        }
   }
    //需求2
    for (let i = 0; i < userAge.length; i++) {
      if (userAge[i]>=18)
       document.write(`已经成人的年龄是: ${userAge[i]} <br>`)
    }
   //需求3 
   let sum = 0
   for (let i = 0; i < userAge.length; i++) {
       sum+=userAge[i]
   }
     document.write(`所有人的年龄和是: ${sum} <br>`);
    //需求4
    let average = sum/userAge.length
    document.write(`所有人的平均年龄是: ${average} <br>`);
    //需求5
    let max= userAge[0]
    for (let i = 0; i < userAge.length; i++){
      if (max< userAge[i]){
        max = userAge[i]
      }
     
    }
    document.write(`最大值是: ${max} <br>`);
    let min =userAge[0]
    for (let i = 0; i < userAge.length; i++){
      if (min> userAge[i]){
        min = userAge[i]
      }
    }
       document.write(`最小值是: ${min} <br>`);
 </script> 
</body>
</html>